<?php
// Tim'Roster
// Copyright (c) 2011 Nicolas Nallet <aspgic2@gmail.com>
//
// This file is part of Tim'Roster.
//
// Tim'Roster is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Tim'Roster is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

$xml_config = simplexml_load_file('config.xml');

include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/class/Item_Family.php');

if ((isset($_POST['type'])) && (is_numeric($_POST['type']))){
//    echo generate_item_family_dropdown($_GET['type']);


    $fam_array = Item_Family::get_family($_POST["type"]);



    echo 'var s = document.forms["'.$_POST["form"].'"].elements["'.$_POST["select"].'"];';
    echo 's.options.length = 0;';
//    echo 's.options[s.options.length] = new Option("","");';
    echo 'var opt = null;';

    for ($i = 0; $i < count($fam_array); $i++) {

        echo 'opt = new Option("'.$fam_array[$i]->get_label().'", "'.$fam_array[$i]->get_id().'");';
        echo 'opt.title = "'.$fam_array[$i]->get_icon().'";';
        echo 's.options[s.options.length] = opt;';

//        echo 's.options[s.options.length] = new Option("'.$fam_array[$i]->get_label().'", "'.$fam_array[$i]->get_id().'");';
    }
}




if ((isset($_POST['family'])) && (is_numeric($_POST['family']))){
//    echo generate_item_code_dropdown($_GET['family']);

    $code_array = Item_Code::get_item_code($_POST["family"]);
    
    echo 'var s = document.forms["'.$_POST["form"].'"].elements["'.$_POST["select"].'"];';
    echo 's.options.length = 0;';
//    echo 's.options[s.options.length] = new Option("","");';

    for ($i = 0; $i < count($code_array); $i++) {
        echo 's.options[s.options.length] = new Option("'.$code_array[$i]->get_label().'", "'.$code_array[$i]->get_code().'");';
    }
}











?>
